package com.mytrip.webapp.action.login;

import java.util.List;

import com.mytrip.base.action.StrutsActionAdapter;
import com.mytrip.dto.BackOperatorDto;
import com.mytrip.model.BackOperator;
import com.mytrip.model.MytripTest;
import com.mytrip.service.BackOperatorManager;
import com.mytrip.service.MytripTestManager;
import com.mytrip.service.RoleManager;
import com.mytrip.util.MD5Support;

public class BackendLoginAction extends StrutsActionAdapter{
	private static final long serialVersionUID = -3762758888845664440L;

	private BackOperatorDto backOperatorDto;

	private BackOperatorManager backOperatorManager;

	private MytripTestManager mytripTestManager;
	
	private List<MytripTest> mytripTestList;

	@SuppressWarnings("unused")
	private RoleManager roleManager;

	public BackOperatorDto getBackOperatorDto(){
		return backOperatorDto;
	}

	public void setRoleManager(RoleManager roleManager){
		this.roleManager = roleManager;
	}

	public void setBackOperatorDto(BackOperatorDto backOperatorDto){
		this.backOperatorDto = backOperatorDto;
	}

	public void setBackOperatorManager(BackOperatorManager backOperatorManager){
		this.backOperatorManager = backOperatorManager;
	}

	public void setMytripTestManager(MytripTestManager mytripTestManager){
		this.mytripTestManager = mytripTestManager;
	}

	// ~ method =================================================================

	public String view() throws Exception{
		// mcSites = McSiteConfigFactory.getInstance().findSites();
		return SUCCESS;
	}

	public String login() throws Exception{
		// if (backOperatorDto==null || backOperatorDto.getExactUserName() == null ||
		// "".equals(backOperatorDto.getExactUserName().trim())){
		// this.addActionError("W0000001");
		// return INPUT;
		// }
		//
		// if (backOperatorDto.getPassword() == null || "".equals(backOperatorDto.getPassword().trim())){
		// this.addActionError("W0000001");
		// return INPUT;
		// }
		//		
		// Integer defaultAdminSiteId =
		// backOperatorDto.getDefaultAdminSiteId()!=null?backOperatorDto.getDefaultAdminSiteId():0;
		//		
		// BackOperator bo = backOperatorManager.login(backOperatorDto.getExactUserName(),
		// backOperatorDto.getPassword(), defaultAdminSiteId);
		// if (bo==null) {
		// this.addActionError("W0000001");
		// return INPUT;
		// }

		// mcSites = McSiteConfigFactory.getInstance().findSites();

		// return SUCCESS;

		mytripTestList = mytripTestManager.testGetAll();
		return "test";
	}

	public boolean checkLogin(String userName, String password){
		// password = MD5Support.MD5(password);
		// return backOperatorManager.checkLogin(userName,password) != null;
		return true;
	}

	public List<MytripTest> getMytripTestList(){
		return mytripTestList;
	}

	public void setMytripTestList(List<MytripTest> mytripTestList){
		this.mytripTestList = mytripTestList;
	}

}
